import logging

import allure
import jsonpath

from utils.send_request import send_sql_request

def http_assert(case,res):
    with allure.step("http响应断言/http的json断言"):
        logging.info(f"http响应断言/http的json断言,根据{case['http_check']}断言,期望结果为{case['http_expected']}")
        if case["http_check"]:
            result=jsonpath.jsonpath(res.json(), case["http_check"])[0]
            assert result == case["http_expected"]
        else:
            assert case["http_expected"] in res.text

def sql_assert(case):
    with allure.step("sql响应断言"):
        logging.info(f"sql响应断言,根据{case['sql_check']}断言,期望结果为{case['sql_expected']}")
        if case["sql_check"] and case["sql_expected"]:
            result=send_sql_request(case["sql_check"])
            assert result == case["sql_expected"]
